//
//  CWvisitView.swift
//  weibo10
//
//  Created by Apple on 16/5/13.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

class CWvisitView: UIView {

    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        prepareUI()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func prepareUI(){
    
        self.addSubview(iconView)
        self.addSubview(homeView)
        self.addSubview(message)
        self.addSubview(register)
        self.addSubview(loginBtn)
        
        
        iconView.translatesAutoresizingMaskIntoConstraints = false
        homeView.translatesAutoresizingMaskIntoConstraints = false
        message.translatesAutoresizingMaskIntoConstraints = false
        register.translatesAutoresizingMaskIntoConstraints = false
        loginBtn.translatesAutoresizingMaskIntoConstraints = false
    
        self.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
        self.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: -40))
        
        
        self.addConstraint(NSLayoutConstraint(item: homeView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
        self.addConstraint(NSLayoutConstraint(item: homeView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
        
        self.addConstraint(NSLayoutConstraint(item: message, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
        self.addConstraint(NSLayoutConstraint(item: message, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 240))
        self.addConstraint(NSLayoutConstraint(item: message, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))

        self.addConstraint(NSLayoutConstraint(item: register, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: message, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0))
        self.addConstraint(NSLayoutConstraint(item: register, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: message, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
        self.addConstraint(NSLayoutConstraint(item: register, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100))
        self.addConstraint(NSLayoutConstraint(item: register, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 35))
        
        
        self.addConstraint(NSLayoutConstraint(item: loginBtn, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: message, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: 0))
        self.addConstraint(NSLayoutConstraint(item: loginBtn, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: message, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 16))
        self.addConstraint(NSLayoutConstraint(item: loginBtn, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100))
        self.addConstraint(NSLayoutConstraint(item: loginBtn, attribute: NSLayoutAttribute.Height, relatedBy:NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 36))
    
    }
    
    
    
    
    
//MARK: - 懒加载子控件
    
    private lazy var iconView : UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    private lazy var homeView : UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    private lazy var message : UILabel = {
    
        let message = UILabel()
        message.text = "关注一些人,看看有什么惊喜!关注一些人,看看有什么惊喜!关注一些人,看看有什么惊喜!关注一些人,看看有什么惊喜!关注一些人,看看有什么惊喜!"
        message.textColor = UIColor.blackColor()
        message.font = UIFont.systemFontOfSize(16)
        message.textAlignment = NSTextAlignment.Center
        message.numberOfLines = 0
        message.sizeToFit()
        return message
    }()
    
    
    
    private lazy var loginBtn : UIButton = {
    
    let btn  = UIButton()
       
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState:  UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        btn.setTitle("注册", forState: UIControlState.Normal)
    return btn
    }()
    
    
    private lazy var register : UIButton = {
    let btn = UIButton()
    btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
    btn.setTitle("登录", forState: UIControlState.Normal)
    btn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
    return btn
    }()
}
